export const SAVE_KEYWORD = 'SAVE_KEYWORD'
export const SAVE_VISIBLE = 'SAVE_VISIBLE'
export const SAVE_APPOINTMENT_PANEL = 'SAVE_APPOINTMENT_PANEL'
export const SAVE_QUERY_PARAMS = 'SAVE_QUERY_PARAMS'

const userMatcher = {
  namespaced: true,
  state: {
    // 关键字
    keyword: '',
    // 是否可见
    visible: false,
    queryParams: {
      pageNum: 1,
      pageSize: 10,
    },
    appointmentPanel: {},
    // 匹配白名单
    whiteList: ['/shop', '/tc', '/doctor'],
    //全局匹配白名单
    globalWhiteList: ['/shop'],
  },
  mutations: {
    [SAVE_KEYWORD](state, { value }) {
      state.keyword = value
    },
    [SAVE_VISIBLE](state, { value }) {
      state.visible = value
    },
    [SAVE_APPOINTMENT_PANEL](state, { value }) {
      state.appointmentPanel = value
    },
    [SAVE_QUERY_PARAMS](state, { value }) {
      state.queryParams = value
    },
  },
  actions: {
    async initUserMatcher(context) {
      context.commit({
        type: SAVE_KEYWORD,
        value: '',
      })
      context.commit({
        type: SAVE_VISIBLE,
        value: false,
      })
      context.commit({
        type: SAVE_QUERY_PARAMS,
        value: {
          pageNum: 1,
          pageSize: 10,
        },
      })
    },
  },
}

export default userMatcher
